package com.douqu.game.core.config.task;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.util.CoreUtils;

import java.util.Arrays;

/**
 * @author: Gavin.
 * Description:
 * Date: 2017/10/21 0021 下午 5:14
 * Huan Yu Copyright (c) 2017 All Rights Reserved.
 */
public class TaskConfig extends GameObject {

    public String dialogueGroup;

    public String icon;

    /**类型*/
    public int type;

    /**目标*/
    public int target;

    /**需求*/
    public int [] demand ;

    /**需求描述*/
    public String describe;

    /**任务接取等级*/
    public int takeGrade;

    public int groupId;

    public int sequence;

    /**道具掉落*/
    public CommonData [] props;

    /**资源掉落*/
    public CommonData [] assets;

    /**卡片掉落配置*/
    public CommonData [] cards;

    /**跳转*/
    public String skip;

    /**成长值*/
    public int growthValue;

    /**活跃值*/
    public int activeValue;

    /****/
    public int showNum;

    public int transition;

    @Override
    public boolean check() {
        if(props == null)
        {
            LogUtils.error("Task check props is null -> id:" + id + " name:" + name);
            return false;
        }

        if(assets == null)
        {
            LogUtils.error("Task check assets is null -> id:" + id + " name:" + name);
            return false;
        }

        if(cards == null)
        {
            LogUtils.error("Task check cards is null -> id:" + id + " name:" + name);
            return false;
        }
        if(demand == null || demand.length == 0)
        {
            LogUtils.error("Load Task demand Error1 -> id:" + id + " name:" + name);
            return false;
        }
        return true;
    }





    @Override
    public boolean setVariable(String key, String value) {

        if("props".equals(key))
        {
            props = LoadUtils.loadCommonDataToArray(key, value);
            return LoadUtils.checkCommonData(props, this.getClass(), key, DataFactory.PROP_KEY, id);
        }
        else if("assets".equals(key))
        {
            assets = LoadUtils.loadCommonDataToArray(key, value);
            return LoadUtils.checkCommonData(assets, this.getClass(), key, DataFactory.ASSET_KEY, id);
        }
        else if("cards".equals(key))
        {
            cards = LoadUtils.loadCommonDataToArray(key, value);
            return LoadUtils.checkCommonData(cards, this.getClass(), key, DataFactory.CARD_KEY, id);

        }
        else if("demand".equals(key))
        {
            if(CoreUtils.isNullOrEmpty(value))
            {
                LogUtils.error("Load Task demand Error -> id:" + id + " value:" + value);
                return false;
            }
            else
            {
                demand = LoadUtils.loadIntArray(key, value);
            }
            return true;
        }
        else
            return super.setVariable(key, value);
    }

    @Override
    public String toString() {
        return "Task{" +
                "type=" + type +
                ", target=" + target +
                ", demand=" + demand +
                ", describe='" + describe + '\'' +
                ", takeGrade=" + takeGrade +
                ", groupId=" + groupId +
                ", sequence=" + sequence +
                ", props=" + Arrays.toString(props) +
                ", assets=" + Arrays.toString(assets) +
                ", cards=" + Arrays.toString(cards) +
                ", skip='" + skip + '\'' +
                ", growthValue=" + growthValue +
                ", activeValue=" + activeValue +
                '}';
    }
}
